/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package br.com.jr2tecnologia.model;

import br.com.jr2tecnologia.model.entity.Carrier;
import br.com.jr2tecnologia.model.persistence.DAOException;
import br.com.jr2tecnologia.model.persistence.DAOFactory;
import br.com.jr2tecnologia.model.repository.CarrierRepository;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceException;

/**
 *
 * @author ronildo
 */

@Stateless
public class CarrierPersistence implements CarrierPersistenceLocal{
    
    @PersistenceContext
    private EntityManager em;
    private CarrierRepository carrierRepository;
    
    @PostConstruct
    public void initialize(){
        carrierRepository = DAOFactory.getCarrierRepository(em);
    }

    public Carrier findById(Long id){
        return carrierRepository.findById(id);
    }

    public Carrier getDefaultCarrier(){
        return carrierRepository.findById(1l);
    }

    public List<Carrier> list() {
        try{
            return carrierRepository.list();
        }catch(DAOException ex){
            throw new PersistenceException(ex);
        }
    }

}
